package Ajedrez.visual.Tablero;

import java.awt.*;

import javax.swing.*;

public class TextAreas extends JPanel
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	JTextArea Movimientos;
	public static JPanel Blancas;
	public static JPanel Negras;
	JPanel p;
	int[][] a;
	
	public TextAreas()
	{
		Movimientos = new JTextArea();
		Blancas = new JPanel();
		Negras = new JPanel();
		p = new JPanel();
		
		Movimientos.setColumns(20);
		Movimientos.setRows(10);
		Movimientos.setEditable(false);
		JScrollPane scrollPane = new JScrollPane(Movimientos, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
		
		p.setBorder(BorderFactory.createLineBorder(Color.gray, 2));
		p.add(scrollPane);
		
		Blancas.setBorder(BorderFactory.createLineBorder(Color.gray, 2));
		Blancas.setLayout(new GridLayout(2, 5));

		Negras.setBorder(BorderFactory.createLineBorder(Color.gray, 2));
		Negras.setLayout(new GridLayout(2, 5));
		
		anyadirImagenesBlancas();
		anyadirImagenesNegras();
		
		for(int i = 0; i < 5; i++)
		{
			JPanel p1 = new JPanel();
			p1.setLayout(new BorderLayout());
			p1.add(new JLabel("      0"), "Center");
			Blancas.add(p1);
			JPanel p2 = new JPanel();
			p2.setLayout(new BorderLayout());
			p2.add(new JLabel("      0"), "Center");
			Negras.add(p2);
		}
		
		this.setLayout(new GridLayout(3, 1));
		this.add(p);
		this.add(Blancas);
		this.add(Negras);
		this.setSize(300, 162);
	}
	
	private static void anyadirImagenesBlancas()
	{
		Blancas.add(new JLabel(new ImageIcon("resources/images/PiezasPequenas/PeonBlanco.png")));
		Blancas.add(new JLabel(new ImageIcon("resources/images/PiezasPequenas/AlfilBlanco.png")));
		Blancas.add(new JLabel(new ImageIcon("resources/images/PiezasPequenas/CaballoBlanco.png")));
		Blancas.add(new JLabel(new ImageIcon("resources/images/PiezasPequenas/TorreBlanca.png")));
		Blancas.add(new JLabel(new ImageIcon("resources/images/PiezasPequenas/ReinaBlanca.png")));
	}
	
	private static void anyadirImagenesNegras()
	{
		Negras.add(new JLabel(new ImageIcon("resources/images/PiezasPequenas/PeonNegro.png")));
		Negras.add(new JLabel(new ImageIcon("resources/images/PiezasPequenas/AlfilNegro.png")));
		Negras.add(new JLabel(new ImageIcon("resources/images/PiezasPequenas/CaballoNegro.png")));
		Negras.add(new JLabel(new ImageIcon("resources/images/PiezasPequenas/TorreNegra.png")));
		Negras.add(new JLabel(new ImageIcon("resources/images/PiezasPequenas/ReinaNegra.png")));
	}
	
	public static void anyadirCaptura(int[][] a, boolean b)
	{
		if(b)
		{
			Blancas.removeAll();
			Blancas.repaint();
			anyadirImagenesBlancas();
			for(int i = 0; i < 5; i++)
			{
				JPanel p = new JPanel();
				p.setLayout(new BorderLayout());
				p.add(new JLabel("      " + a[i][0]), "Center");
				Blancas.add(p);
			}
			Blancas.repaint();
		}
		else
		{
			Negras.removeAll();
			Negras.repaint();
			anyadirImagenesNegras();
			for(int i = 0; i < 5; i++)
			{
				JPanel p = new JPanel();
				p.setLayout(new BorderLayout());
				p.add(new JLabel("      " + a[i][1]), "Center");
				Negras.add(p);
			}
			Negras.repaint();
		}
	}
	
	public static void main(String[] args)
	{
		JFrame f = new JFrame();
		f.add(new TextAreas());
		f.setSize(300, 200);
		f.setVisible(true);
	}

}
